function [chi_eff] = EffSolZen(chi, chi0)
%
% Effective Solar Zenith Angle
%
%DESCRIPTION:
%This function computes the Effective Solar Zenith Angle (chi_eff) as
%function of the Solar Zenit Angle (chi) and the Solar Zenoth Night
%Transition (chi0).
%
%PROTOTYPE:
% [chi_eff] = EffSolZen(chi)
% [chi_eff] = EffSolZen(chi, chi0)
%
%--------------------------------------------------------------------------
% INPUTS:
%   chi        [1x1]       Solar Zenith Angle        [deg]
%   chi0       [1x1]       Sol. Zen. Night Trans.    [deg] (optional)
%--------------------------------------------------------------------------
% OUTPUTS:
%   chi_eff    [1x1]       Effective Solar Zen. An.  [deg]
%--------------------------------------------------------------------------
%
%NOTES:
% (none)
%
%CALLED FUNCTIONS:
% (none)
%
%UPDATES:
% (none)
%
%REFERENCES:
% [1] "Ionospheric Correction Algorithm for Galileo Single-Frequency Users"
%      - European GNSS (Galileo) Open Service
%
%AUTHOR(s):
%Luigi De Maria, Matteo D'Addazio, 2022
%

%% Main Code

%Solar Zenith Angle at Day Night Transition [deg]
if nargin == 1
    chi0 = 86.23292796211615;
end

%Effective Solar Zenith Angle
Echi = exp(12*(chi-chi0));
if Echi > 1e306
    Echi = 1e306;
end
chi_eff = (chi + (90 - 0.24*exp(20 - 0.2*chi)) * Echi) /...
          (1 + Echi);

end